<template>
  <view class="container">
    <Table ref="table" :fetchData="fetchData" :autoFetch="false">
      <template #default="{ data }">
        <uni-card
          @click="cardClick(item)"
          v-for="item in data"
          :title="item.pointName"
          :extra="item.checkState"
          :sub-title="item.checkInfo"
        >
        </uni-card>
      </template>
    </Table>
  </view>
</template>
<script>
export default {
  data() {
    return {
      id: "",
    };
  },
  onLoad(payload) {
    this.id = payload.id;
  },
};
</script>
<script setup>
import { ref, getCurrentInstance, onMounted, reactive } from "vue";
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import Table from "@/components/uniList.vue";
import { useAsyncData } from "@/hooks/useAsyncData.js";
import { taskPoints } from "@/api/znxj/xjrw.js";
import { router } from "@/router/index.js";

const cardClick = (item) => {
  router.toPage({
    path: "/pages/znxj/xjrw/components/input",
    params: {
      row: JSON.stringify(item),
    },
  });
};
const table = ref();
const filterForm = reactive({
  pageSize: 9999,
});
const { fetchData, getList, queryParams } = useAsyncData({
  table,
  APIS: taskPoints,
  filterForm,
});
const points = ref([]);
const planTaskState = ref("");

onMounted(async () => {
  const { id } = getCurrentInstance().data;
  filterForm.pointId = id;
  filterForm.checkState = '未排查';
  points.value = await getList();
  planTaskState.value = state;
});

const saoyisao = () => {
  // 只允许通过相机扫码
  uni.scanCode({
    // onlyFromCamera: true,
    success: function (res) {
      let pointId = ''
      try{
       pointId = JSON.parse(res.result).id
      }catch(e){
        pointId = res.result
      }
      const node = points.value.find((item) => item.pointId == pointId);
      // const node = points.value.find(item => item.pointId == 14)
      if (node) {
        router.toPage({
          path: "/pages/znxj/xjrw/components/input",
          params: {
            row: JSON.stringify(node),
          },
        });
      } else {
        uni.showToast({
          title: "该点位不在任务中",
          icon: "error",
        });
      }
    },
  });
};
</script>

<style lang="scss" scoped>
.container {
  padding-bottom: 12vw;
}
.saoyisao {
  position: fixed;
  bottom: 0;
  width: 100vw;
  height: 12vw;
  left: 0;
  right: 0;
}
</style>
